<template>
  <div class="vip-page">
    <!-- Banner -->
    <section class="vip-banner" :style="{ backgroundImage: `url(${bannerUrl})` }">
      <div class="vip-banner__mask"></div>
      <div class="vip-banner__content">
        <div class="vip-banner__header">
          <h1 class="vip-title">超级会员专享服务，招聘快人一步</h1>
          <el-button type="primary" class="vip-cta" @click="openVip">开通VIP特权</el-button>
        </div>
        <!-- 前5个特权：白色卡片，放在Banner底部 -->
        <div class="vip-banner__features">
          <div v-for="f in coreFeatures" :key="f.title" class="feature-card">
            <img class="feature-icon" :src="f.icon" :alt="f.title" />
            <div class="feature-info">
              <h3 class="feature-title">{{ f.title }}</h3>
              <p class="feature-desc">{{ f.desc }}</p>
            </div>
          </div>
        </div>
      </div>
    </section>

    <!-- 更多会员特权 -->
    <section class="more-features">
      <h2 class="section-heading">更多会员特权</h2>
      <div class="more-grid">
        <div v-for="m in moreFeatures" :key="m.title" class="more-item">
          <img :src="m.icon" :alt="m.title" class="more-icon" />
          <div class="more-texts">
            <div class="more-title">{{ m.title }}</div>
            <div class="more-desc">{{ m.desc }}</div>
          </div>
        </div>
      </div>
    </section>

    <!-- VIP对比 -->
    <section class="privilege-comparison">
      <h2 class="section-heading">会员特权对比</h2>
      <div class="privilege-cards">
        <!-- 功能特权卡片 -->
        <div class="privilege-card feature-card-list">
          <div class="card-header">
            <div class="card-icon-placeholder"></div>
            <h3 class="card-title">功能特权</h3>
          </div>
          <div class="card-body">
            <div v-for="item in privilegeList" :key="item.feature" class="feature-item">
              {{ item.feature }}
            </div>
          </div>
        </div>

        <!-- 超级会员卡片 -->
        <div class="privilege-card vip-card">
          <img :src="vipCornerIcon" alt="VIP" class="vip-corner-badge" />
          <div class="card-header">
            <img :src="svipIcon" alt="SVIP" class="card-icon" />
            <h3 class="card-title">超级会员</h3>
          </div>
          <div class="card-body">
            <div v-for="(item, index) in privilegeList" :key="item.feature" class="feature-item">
              <img v-if="index === 0 || index >= 6" :src="canIcon" alt="支持" class="status-icon" />
              <span v-else class="feature-text">{{ item.vip }}</span>
            </div>
          </div>
        </div>

        <!-- 非会员卡片 -->
        <div class="privilege-card normal-card">
          <div class="card-header">
            <img :src="nonvipIcon" alt="普通用户" class="card-icon" />
            <h3 class="card-title">普通用户</h3>
          </div>
          <div class="card-body">
            <div v-for="(item, index) in privilegeList" :key="item.feature" class="feature-item">
              <img v-if="index === 0 || index >= 5" :src="cantIcon" alt="不支持" class="status-icon" />
              <span v-else class="feature-text">{{ item.normal }}</span>
            </div>
          </div>
        </div>
      </div>
    </section>

    <!-- VIP开通弹窗 -->
    <el-dialog
      v-model="showVipDialog"
      title=""
      width="500px"
      :show-close="false"
      class="vip-dialog"
    >
      <div class="vip-dialog-content">
        <div class="vip-dialog-header">
          <div class="vip-crown">👑</div>
          <h2 class="vip-dialog-title">开通超级会员</h2>
          <p class="vip-dialog-subtitle">享受全方位招聘特权服务</p>
        </div>
        
        <div class="payment-section">
          <h3 class="payment-title">选择支付方式</h3>
          <div class="payment-options">
            <label class="payment-option">
              <input
                type="radio"
                value="2"
                v-model="selectedPayMethod"
                class="payment-radio"
              />
              <div class="payment-content">
                <img :src="alipayIcon" alt="支付宝" class="payment-icon" />
                <span class="payment-text">支付宝</span>
              </div>
              <div class="radio-indicator"></div>
            </label>
          </div>
        </div>
        
        <div class="vip-price-info">
          <div class="price-desc">立即享受所有VIP特权服务</div>
        </div>
      </div>
      
      <template #footer>
        <div class="vip-dialog-footer">
          <el-button @click="closeVipDialog" class="cancel-btn">取消</el-button>
          <el-button 
            type="primary" 
            @click="confirmPayment"
            class="confirm-btn"
            :loading="paymentLoading"
          >
            {{ paymentLoading ? '处理中...' : '确认开通' }}
          </el-button>
        </div>
      </template>
    </el-dialog>
  </div>
  
</template>

<script setup>
import { ref } from 'vue'
import { ElMessage } from 'element-plus'
import { createVipOrder } from '../../api/company'
import bannerUrl from '../../assets/images/controlPanel/bg_banner_svip.png'
import analyse from '../../assets/images/controlPanel/analyse.png'
import candidate from '../../assets/images/controlPanel/candidate.png'
import jobIcon from '../../assets/images/controlPanel/职位.png'
import excel from '../../assets/images/controlPanel/excel.png'
import resume from '../../assets/images/controlPanel/resume.png'
import service from '../../assets/images/controlPanel/service.png'
import talent from '../../assets/images/controlPanel/talent.png'
import customization from '../../assets/images/controlPanel/customization.png'
import guidance from '../../assets/images/controlPanel/guidance.png'
import echarts from '../../assets/images/controlPanel/echarts.png'
import svipIcon from '../../assets/images/controlPanel/svip.png'
import nonvipIcon from '../../assets/images/controlPanel/nonvip.png'
import vipCornerIcon from '../../assets/images/controlPanel/VIP.png'
import canIcon from '../../assets/images/controlPanel/can.png'
import cantIcon from '../../assets/images/controlPanel/cant.png'
import alipayIcon from '../../assets/images/controlPanel/alipay.png'

const coreFeatures = [
  { title: '行业分析', desc: '图表洞察趋势，辅助招聘决策', icon: analyse },
  { title: '候选人管理', desc: '无限制查看候选人', icon: candidate },
  { title: '职位管理', desc: '无限制查看职位', icon: jobIcon },
  { title: '报表下载', desc: '候选人、职位 Excel 下载', icon: excel },
  { title: '简历下载', desc: '无限制任意下载简历', icon: resume }
]

const moreFeatures = [
  { title: '全天候客服', desc: '7×24小时在线响应，问题即时解决', icon: service },
  { title: '人才推荐', desc: '智能匹配优质候选人，高效锁定目标', icon: talent },
  { title: '企业定制', desc: '按需定制招聘流程与策略', icon: customization },
  { title: '大数据分析', desc: '多维数据洞察招聘趋势与效果', icon: echarts },
  { title: '一对一指导', desc: '专家顾问陪伴式优化招聘方案', icon: guidance }
]

const privilegeList = [
  { feature: '图表分析', vip: '√ 无限制', normal: '✗' },
  { feature: '候选人库', vip: '√ 无限制', normal: '仅限3个月' },
  { feature: '职位管理', vip: '√ 无限制', normal: '仅限3个月' },
  { feature: '报表下载', vip: '√ 无限次', normal: '不提供下载，仅供查看' },
  { feature: '简历下载', vip: '√ 无限次', normal: '不提供下载，仅供查看' },
  { feature: '客服服务', vip: '√ 7×24随时服务', normal: '✗' },
  { feature: '人才推荐', vip: '√', normal: '✗' },
  { feature: '大数据分析', vip: '√', normal: '✗' }
]

// 响应式数据
const showVipDialog = ref(false)
const selectedPayMethod = ref('2') // 默认支付宝支付
const paymentLoading = ref(false)

const openVip = () => {
  showVipDialog.value = true
}

const closeVipDialog = () => {
  showVipDialog.value = false
  paymentLoading.value = false
}

const confirmPayment = async () => {
  try {
    paymentLoading.value = true
    
    const response = await createVipOrder(selectedPayMethod.value)
    
    console.log('VIP开通响应结果:', response)
      // 创建一个临时的div来解析HTML
      const tempDiv = document.createElement('div')
      tempDiv.innerHTML = response
      
      // 查找表单元素
      const form = tempDiv.querySelector('form')
      if (form) {
        // 将表单添加到当前页面并自动提交
        document.body.appendChild(form)
        form.submit()
        
        // 关闭弹窗
        closeVipDialog()
        ElMessage.success('正在跳转到支付页面...')
      } else {
        throw new Error('未找到有效的支付表单')
      }
    
  } catch (error) {
    console.error('VIP开通失败:', error)
    ElMessage.error('开通失败，请稍后重试')
  } finally {
    paymentLoading.value = false
  }
}
</script>

<style scoped>
/* 页面容器（不增加外部 padding） */
.vip-page { display: flex; flex-direction: column; }

/* Banner 区域 */
.vip-banner {
  position: relative;
  width: 100%;
  height: 420px;
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
  border-radius: 0;
  overflow: hidden;
}

.vip-banner__mask {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(0,0,0,0.35) 0%, rgba(0,0,0,0.55) 100%);
}

.vip-banner__content {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  text-align: center;
  padding: 40px 1rem 20px 1rem;
}

.vip-banner__header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.vip-title {
  margin: 0;
  font-size: 28px;
  font-weight: 700;
  color: #e7bd77;
  letter-spacing: 1px;
}

.vip-cta {
  background-color: #e7bd77;
  border-color: #e7bd77;
  color: #1f2329;
  font-weight: 600;
  font-size: 16px;
  padding: 12px 32px;
  height: auto;
}

.vip-cta:hover {
  background-color: #d8ac65;
  border-color: #d8ac65;
}

/* Banner 内部的核心特权卡片 */
.vip-banner__features {
  width: 92%;
  max-width: 1120px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
}

.feature-card {
  background: #ffffff;
  border: 1px solid rgba(0,0,0,0.06);
  border-radius: 10px;
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 12px;
  box-shadow: 0 6px 18px rgba(0,0,0,0.12);
  transition: all 0.3s ease;
  cursor: pointer;
}

.feature-card:hover {
  transform: translateY(-8px);
  box-shadow: 0 12px 32px rgba(0,0,0,0.18);
  border-color: #e7bd77;
}

.feature-card:hover .feature-title {
  color: #e7bd77;
}

.feature-card:hover .feature-icon {
  transform: scale(1.1);
}

.feature-icon {
  width: 56px;
  height: 56px;
  object-fit: contain;
  transition: transform 0.3s ease;
}

.feature-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: center;
}

.feature-title {
  margin: 0;
  font-size: 16px;
  color: #2d3748;
  font-weight: 600;
  transition: color 0.3s ease;
}

.feature-desc {
  margin: 0;
  color: #718096;
  font-size: 13px;
}

/* 更多特权（无卡片背景，紧贴白色区域） */
.more-features {
   margin: 0 40px; 
   padding: 20px 0; 
  }

.section-heading {
  margin: 0 0 14px 0;
  font-size: 18px;
  color: #2d3748;
  font-weight: 700;
  text-align: center;
}

.more-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 20px;
}

.more-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 12px;
  padding: 16px 8px;
  border-radius: 8px;
  transition: all 0.3s ease;
  cursor: pointer;
}

.more-item:hover {
  transform: translateY(-4px);
  background: rgba(231, 189, 119, 0.08);
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
}

.more-item:hover .more-title {
  color: #e7bd77;
}

.more-item:hover .more-icon {
  transform: scale(1.1);
}

.more-icon {
  width: 48px;
  height: 48px;
  object-fit: contain;
  transition: transform 0.3s ease;
}

.more-texts { 
  display: flex; 
  flex-direction: column; 
  gap: 4px; 
  align-items: center;
}
.more-title { 
  color: #2d3748; 
  font-size: 14px; 
  font-weight: 600; 
  transition: color 0.3s ease;
}
.more-desc { 
  color: #718096; 
  font-size: 12px; 
}

/* VIP对比 */
.privilege-comparison {
  margin: 40px 0;
  padding: 0 20px;
}

.privilege-cards {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  max-width: 900px;
  margin: 0 auto;
  position: relative;
}

.privilege-card {
  position: relative;
  background: #ffffff;
  box-shadow: 0 4px 20px rgba(0,0,0,0.08);
  overflow: visible;
  width: 280px;
  margin: 0 -10px;
  height: 580px;
  display: flex;
  flex-direction: column;
}

.feature-card-list {
  z-index: 1;
}

.vip-card {
  background: #fff9ea;
  border: 2px solid #e7bd77;
  z-index: 3;
  transform: translateY(-8px);
  box-shadow: 0 8px 32px rgba(231, 189, 119, 0.3);
}

.normal-card {
  z-index: 2;
}

/* 确保内容区域对齐 */
.feature-card-list .card-body,
.normal-card .card-body {
  margin-top: 8px;
}

.vip-corner-badge {
  position: absolute;
  top: 0;
  right: 0;
  width: 40px;
  height: 40px;
  object-fit: contain;
  transform: rotate(45deg);
  transform-origin: 50% 50%;
  z-index: 4;
}

.vip-card::after {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 0 65px 65px 0;
  border-color: transparent #ffb70a transparent transparent;
  z-index: 3;
}

.card-header {
  padding: 24px 20px 16px;
  text-align: center;
}

.card-icon {
  width: 48px;
  height: 48px;
  object-fit: contain;
  margin-bottom: 12px;
}

.card-icon-placeholder {
  width: 48px;
  height: 48px;
  margin-bottom: 12px;
}

.card-title {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  color: #2d3748;
}

.card-body {
  padding: 20px;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.feature-item {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px 0;
  border-bottom: 1px solid rgba(0,0,0,0.05);
  font-size: 14px;
  height: 48px;
  flex-shrink: 0;
}

.feature-item:last-child {
  border-bottom: none;
}

.feature-card-list .feature-item {
  justify-content: flex-start;
  font-weight: 600;
  color: #2d3748;
  padding-left: 20px;
}

.status-icon {
  width: 24px;
  height: 24px;
  object-fit: contain;
}

.feature-text {
  color: #2d3748;
  font-weight: 500;
  text-align: center;
}

/* VIP弹窗样式 */
:deep(.vip-dialog) {
  border-radius: 16px;
  overflow: hidden;
}

:deep(.vip-dialog .el-dialog__header) {
  display: none;
}

:deep(.vip-dialog .el-dialog__body) {
  padding: 0;
}

:deep(.vip-dialog .el-dialog__footer) {
  padding: 0;
}

.vip-dialog-content {
  background: linear-gradient(135deg, #fff9ea 0%, #fef3e4 100%);
  padding: 32px;
  text-align: center;
}

.vip-dialog-header {
  margin-bottom: 32px;
}

.vip-crown {
  font-size: 48px;
  margin-bottom: 16px;
}

.vip-dialog-title {
  margin: 0 0 8px 0;
  font-size: 24px;
  font-weight: 700;
  color: #2d3748;
  background: linear-gradient(135deg, #e7bd77 0%, #d4a574 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.vip-dialog-subtitle {
  margin: 0;
  color: #6b7280;
  font-size: 14px;
}

.payment-section {
  margin-bottom: 24px;
}

.payment-title {
  margin: 0 0 16px 0;
  font-size: 16px;
  font-weight: 600;
  color: #2d3748;
  text-align: left;
}

.payment-options {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.payment-option {
  position: relative;
  display: flex;
  align-items: center;
  padding: 16px;
  border: 2px solid #e5e7eb;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.3s ease;
  background: #ffffff;
}

.payment-option:hover {
  border-color: #e7bd77;
  box-shadow: 0 4px 12px rgba(231, 189, 119, 0.2);
}

.payment-radio {
  position: absolute;
  opacity: 0;
  cursor: pointer;
}

.payment-radio:checked + .payment-content + .radio-indicator {
  background: #e7bd77;
  border-color: #e7bd77;
}

.payment-radio:checked + .payment-content + .radio-indicator::after {
  opacity: 1;
}

.payment-option:has(.payment-radio:checked) {
  border-color: #e7bd77;
  background: rgba(231, 189, 119, 0.05);
}

.payment-content {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
}

.payment-icon {
  width: 32px;
  height: 32px;
  object-fit: contain;
}

.payment-text {
  font-size: 16px;
  font-weight: 500;
  color: #2d3748;
}

.radio-indicator {
  width: 20px;
  height: 20px;
  border: 2px solid #d1d5db;
  border-radius: 50%;
  position: relative;
  transition: all 0.3s ease;
  background: #ffffff;
}

.radio-indicator::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 8px;
  height: 8px;
  background: #ffffff;
  border-radius: 50%;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.vip-price-info {
  background: rgba(255, 255, 255, 0.8);
  border-radius: 12px;
  padding: 20px;
  border: 1px solid rgba(231, 189, 119, 0.3);
}

.price-desc {
  font-size: 16px;
  color: #2d3748;
  font-weight: 500;
}

.vip-dialog-footer {
  background: #ffffff;
  padding: 24px 32px;
  display: flex;
  justify-content: space-between;
  gap: 16px;
}

.cancel-btn {
  flex: 1;
  height: 44px;
  border-color: #d1d5db;
  color: #6b7280;
}

.cancel-btn:hover {
  border-color: #9ca3af;
  color: #4b5563;
}

.confirm-btn {
  flex: 2;
  height: 44px;
  background: linear-gradient(135deg, #e7bd77 0%, #d4a574 100%);
  border: none;
  font-weight: 600;
}

.confirm-btn:hover {
  background: linear-gradient(135deg, #d4a574 0%, #c49669 100%);
}

/* 响应式 */
@media (max-width: 768px) {
  .vip-banner { height: 360px; }
  .vip-title { font-size: 22px; }
  .vip-banner__features { 
    gap: 10px;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  }
  .feature-icon {
    width: 48px;
    height: 48px;
  }
  .feature-card:hover {
    transform: translateY(-4px);
  }
  .more-grid {
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 16px;
  }
  .more-icon {
    width: 40px;
    height: 40px;
  }
  .more-item:hover {
    transform: translateY(-2px);
  }
  
  /* VIP对比移动端适配 */
  .privilege-comparison {
    margin: 20px 0;
    padding: 0 10px;
  }
  
  .privilege-cards {
    flex-direction: column;
    align-items: center;
  }
  
  .privilege-card {
    width: 300px;
    margin: 8px 0;
    height: auto;
  }
  
  .vip-card {
    transform: translateY(0);
    order: -1;
  }
  
  .vip-corner-badge {
    width: 32px;
    height: 32px;
  }
  
  .card-header {
    padding: 20px 16px 12px;
  }
  
  .card-icon {
    width: 40px;
    height: 40px;
    margin-bottom: 8px;
  }
  
  .card-title {
    font-size: 16px;
  }
  
  .card-body {
    padding: 16px;
  }
  
  .feature-item {
    padding: 10px 0;
    font-size: 13px;
  }
  
  .status-icon {
    width: 18px;
    height: 18px;
  }
}
</style>
